package com.lele.js;

import java.io.IOException;

import com.lele.util.FolderUtil;

public class ExtDesktopJS extends SuperJS {
	public ExtDesktopJS(SuperJS sf){
		this.entityName = sf.getEntityName();
		this.entityClass = sf.getEntityClass();
		this.file_url = sf.getProject_root()+"leleCMS\\WebRoot\\admin\\MyDesktop\\App.js";
		this.fields = sf.getFields();
	}
	
	public String getFileURL() {
		return file_url;
	}

	public String getContent(){
		StringBuilder new_actions = new StringBuilder();
		try {
			new_actions.append(FolderUtil.readTxt(
					this.getFileURL().toString(), "UTF-8"));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		StringBuilder requires_str = new StringBuilder();
		requires_str.append("					,'FMApp.").append(entityClass).append("App'");
		requires_str.append("\r\n");
		new_actions.insert(new_actions.indexOf("//requires auto"),
				requires_str.toString());
		
		StringBuilder getModules_str = new StringBuilder();
		getModules_str.append("						,new FMApp.").append(entityClass).append("App()");
		getModules_str.append("\r\n");
		new_actions.insert(new_actions.indexOf("//getModules auto"),getModules_str.toString());
		
		StringBuilder data_str = new StringBuilder();
		data_str.append("												, {");
		data_str.append("\r\n");
		data_str.append("													name : '").append(entityName).append("',");
		data_str.append("\r\n");
		data_str.append("													iconCls : 'admin',");
		data_str.append("\r\n");
		data_str.append("													module : '").append(entityName).append("'");
		data_str.append("\r\n");
		data_str.append("												}");		
		data_str.append("\r\n");
		new_actions.insert(new_actions.indexOf("//data auto"),data_str.toString());
		
		return new_actions.toString();
	}
}
